<!--
 * @Description: In User Settings Edit
 * @Author: your name
 * @Date: 2019-07-30 20:02:30
 * @LastEditTime: 2020-02-28 11:25:38
 * @LastEditors: Please set LastEditors
 -->
<!doctype html>
<html>

<head>
    <meta charset="utf-8">
    <meta name="viewport"
        content="maximum-scale=1.0,minimum-scale=1.0,user-scalable=0,width=device-width,initial-scale=1.0" />
    <meta name="format-detection" content="telephone=no,email=no,date=no,address=no">
    <title>Hello APP</title>
    <link rel="stylesheet" type="text/css" href="../css/vant.css">
    <link rel="stylesheet" type="text/css" href="../css/base.css" />
    <link rel="stylesheet" href="../css/elementui.css">
    <script type="text/javascript" src="../script/jquery.js"></script>
    <script type="text/javascript" src="../script/layer/mobile/layer.js"></script>
    <script type="text/javascript" src="../script/vue.min.js"></script>
    <script type="text/javascript" src="../script/vant.min.js"></script>
    <script type="text/javascript" src="../script/fastclick.js"></script>
    <script type="text/javascript" src="../script/base.js"></script>
    <script src="../script/elementui.js"></script>
    <style>
        .box {
            width: 100%;
            display: flex;
            flex-direction: column;
        }

        .form {
            width: 100%;
            height: auto;
        }

        .content {
            padding: 0 50px;
        }

        .van-field {
            width: 33.33%;
            float: left;
        }

        .van-cell {
            background-color: transparent;
        }

        .van-field__control {
            border-bottom: 2px solid #e6c678;
        }

        .van-cell::after {
            border-bottom: 0;
        }

        .van-cell {
            background-color: transparent;
        }

        .van-cell::after {
            border-bottom: 0;
        }

        .head .van-row .van-col,
        .content .van-row .van-col {
            margin-bottom: 8px;
            text-align: center;
            font-weight: 300;
            color: #e6c678;
            font-size: 14px;
        }

        .content .van-row .van-col .van-field {
            padding: 0;
            background: #fff;
            border: 1px solid #cecece;
            border-radius: 5px;
        }

        .content .van-row .van-col .van-field__control {
            color: #000;
        }

        @keyframes load {
            0% {
                box-shadow: inset 0px 0px 100px 10px rgba(61, 134, 208, 0.6);
            }

            100% {
                box-shadow: inset 0px 0px 20px 10px rgba(61, 134, 208, 0.1);
            }
        }

        .green {
            color: green;
        }

        .red {
            color: red;
        }

        .yellow {
            color: yellow;
        }

        .right-button .van-button {
            margin-left: 5px;
            min-width: 100px;
        }

        .scanImg img {
            width: 40px;
            height: 40px;
        }

        .devicePop {
            height: 50%;
            overflow: auto;
        }

        .devicePop .van-col {
            padding: 5px 8px;
            text-align: center;
        }

        .devicePop .van-col .van-button {
            width: 100%;
        }

        .devicePop .van-col .van-button .van-button__text {
            color: #090909;
        }

        .scanPop {
            width: 160px;
            height: 180px;
            text-align: center;
            background-color: transparent;
            margin: 0;
            padding: 0;
        }

        .van-icon-enlarge {
            font-size: 150px;
            color: #e6c678;
            margin: 0;
            padding: 0;
        }

        .inputClass {
            opacity: 0;
            width: 150px;
        }

        .scanLine {
            position: absolute;
            z-index: 2;
            width: 66%;
            height: 2px;
            transform: translateX(25%);
            background-color: #e6c678;
            animation: scanLineMove 2s infinite;
        }

        .newClass {
            color: red;
        }

        @keyframes scanLineMove {
            from {
                top: 30px;
            }

            to {
                top: 120px;
            }
        }

        .el-radio.is-bordered.is-checked {
            border-color: #e6c678;
        }

        .el-radio__input.is-checked .el-radio__inner {
            border-color: #e6c678;
            background: #e6c678;
        }

        .el-radio__input.is-checked+.el-radio__label {
            color: #e6c678;
        }

        .topLeft {
            width: 50%;
            padding-left: 5px;
        }

        .top .van-button {
            margin-top: 10px;
            margin-left: 5px;
            padding: 10px 20px;
        }

        .el-radio__label {
            color: #fff;
        }
    </style>
</head>

<body>
    <div id="app" v-cloak>
        <div class="box">
            <div class="top">
                <div class="topLeft">
                    <van-button size="small" color="linear-gradient(#fffeaa, #c07d39)" type="primary"
                        @click="onClickLeft">返回</van-button>
                </div>
                <div class="topRight">
                </div>
            </div>
            <div class="content">
                <div class="form">
                    <van-field v-model="formData.BillNO" label="维修单号" placeholder="维修单号" readonly>
                    </van-field>
                    <van-field v-model="formData.ProductName" label="模具名称" placeholder="选择模具" readonly
                        @click="openBaseScreen('模具')">
                    </van-field>
                    <van-field v-model="formData.MouldNo" label="模具编号" placeholder="选择模具" readonly>
                    </van-field>
                    <van-field v-model="formData.WXStartTime.split('T')[0]" label="开始维修时间" placeholder="选择开始维修时间"
                        readonly>
                    </van-field>
                    <van-field v-model="formData.EmplName" label="维修人" placeholder="选择维修人" readonly>
                    </van-field>
                    <!-- <van-field v-model="formData.WXEndTime.split('T')[0]" label="结束维修时间" placeholder="选择结束维修时间"
                        readonly>
                    </van-field>
                    <van-field v-model="formData.EndEmplName" label="结束维修人" placeholder="选择结束维修人" readonly>
                    </van-field> -->
                    <van-field v-model="formData.Reason" label="维修原因" placeholder="请输入维修原因" required>
                    </van-field>
                    <van-field v-model="formData.FRemarks" label="维修备注" placeholder="请输入维修备注">
                    </van-field>
                    <van-field v-model="formData.WXNum" label="前30天维修次数">
                    </van-field>
                </div>

                <div class="table">
                    <table class="table-full">
                        <tr>
                            <th width="8%">操作</th>
                            <th nowrap="nowrap" width="8%">序号</th>
                            <th nowrap="nowrap">维修内容</th>
                            <th nowrap="nowrap" width='30%'>维修结果</th>
                        </tr>

                        <tbody>
                            <tr v-for="(item, index) in checkValue">
                                <td>
                                    <van-icon size="25" name="delete" color="#ee0a24" @click="deleteTable(index)">
                                    </van-icon> &nbsp &nbsp &nbsp
                                    <van-icon size="25" v-if="index == checkValue.length -1" name="add" size="18"
                                        color="#e6c678" @click="addRow"></van-icon>
                                </td>
                                <td nowrap="nowrap">{{index + 1}}</td>
                                <td nowrap="nowrap"> <input type="text" style="color: #fff;border: 0;"
                                        v-model='item.UpkeepItemName'></td>
                                </td>
                                <td nowrap="nowrap" style="width: 30%;">
                                    <el-radio size="mini" v-model="item.FResult" label="0" border>不合格</el-radio>
                                    <el-radio size="mini" v-model="item.FResult" label="1" border>合格</el-radio>
                                    <el-radio size="mini" v-model="item.FResult" label="2" border>待定</el-radio>
                                    <!-- <el-radio size="mini" v-model="item.FResult" label="2" border>良好</el-radio>
                                    <el-radio size="mini" v-model="item.FResult" label="3" border>暂无结果</el-radio> -->
                                </td>
                            </tr>
                        </tbody>
                    </table>
                </div>
            </div>

            <div class="bottom">
                <div class="left-content">
                </div>
                <div class="right-button flex-box">
                    <van-button color="#e6c678" @click="confirmSub" block>{{formData.WXStartTime? '结束维修' : '开始维修'}}

                    </van-button>
                </div>
            </div>
        </div>

        <van-popup v-model="scanShow" class="scanPop">
            <div class="scanLine"></div>
            <van-icon name="enlarge"></van-icon>
            <input id="autoInput" class="inputClass" inputmode="none" type="number" v-model="inputCode" ref="input"
                autofocus @keyup.enter="inputFocus()">
        </van-popup>
    </div>
</body>

<script type="text/javascript">
    var vm;
    apiready = function () {

        api.addEventListener({
            name: 'selectRow'
        }, function (ret, err) {
            var type = ret.value.type;
            var row = ret.value.row;
            if (type == '模具') {
                console.log('row', JSON.stringify(row))
                vm.formData.MouldID = row.MouldID;
                vm.formData.MouldNo = row.MouldNo;
                vm.formData.ProductName = row.ProductName;
                vm.formData.WXNum = row.WXNum;
                vm.getInitData()

            }
        })

        vm = new Vue({
            el: '#app',
            data: {
                formData: {
                    BillNO: '',
                    MouldID: '',
                    MouldNo: '',
                    WXStartTime: '',
                    MaintainEquipmentID: 0,
                    WXNum: '',
                    Reason: '',
                    FRemarks: '',
                    EmplName: '',
                    EmplID: '',
                    ProductName: ''
                },
                checkValue: [{ "MouldID": 0, "UpkeepEquipmentDeID": 0, "MouldNo": "0", "UpkeepItemName": "", "FResult": 0 }],
                // checkValue: [],
                ifConfirm: false,
                scanShow: true,
                inputCode: '',
            },
            created: function () {
                var that = this;

                if (window.localStorage.getItem('clientHeight') != 752) {
                    document.getElementById('app').style.zoom = 0
                } else {
                    document.getElementById('app').style.zoom = 1.5
                }

                that.formData.EmplName = window.localStorage.getItem('loginName')
                that.formData.EmplID = window.localStorage.getItem('pin')
                console.log('that.formData.EmplID', JSON.stringify(that.formData.EmplID))
                if (api.pageParam.historyData) {
                    console.log('api', JSON.stringify(api.pageParam.historyData))

                    that.scanShow = false

                    that.formData = api.pageParam.historyData
                    that.formData.EmplName = window.localStorage.getItem('loginName')
                    that.formData.EmplID = window.localStorage.getItem('pin')

                    that.getInitData()

                }
            },
            methods: {
                getInitData() {
                    var that = this
                    var obj = {
                        MouldID: that.formData.MouldID,
                        MaintainEquipmentID: that.formData.MaintainEquipmentID,
                    }
                    console.log('obj', JSON.stringify(obj))
                    APP.ajax('getDeviceWXTemplate_ZSMJ', obj, function (res) {
                        console.log('res', JSON.stringify(res))

                        if (res.ds.length > 0) {
                            res.ds.map((item) => {
                                item.FResult = item.FResult.toString()
                            })
                            that.checkValue = res.ds
                            console.log(JSON.stringify(that.checkValue))
                        }

                    })
                    // console.log('that.formData', JSON.stringify(that.formData))
                },
                onClickLeft() {
                    api.closeFrame()
                },
                deleteTable(index) {
                    var that = this
                    if (that.checkValue.length == 1) {
                        that.checkValue[0].FResult = ''
                        that.checkValue[0].UpkeepEquipmentDeID = ''
                    } else {
                        that.checkValue.splice(index, 1)
                    }
                },
                addRow() {
                    var that = this
                    var newTable = {
                        MouldID: '',
                        UpkeepItemName: '',
                        FResult: '',
                        UpkeepEquipmentDeID: '',
                        MouldNo: '',
                        UpkeepEquipmentDeID: ''
                    }

                    that.checkValue.push(newTable)
                },
                openBaseScreen: function (str) {
                    var that = this;
                    var obj;
                    if (str == '模具') {
                        obj = {
                            allowClear: false,
                            showSearch: true,
                            searchKey: '',
                            serverSearch: false,
                            searchBy: ['ProductName'],
                            isPaging: false,
                            type: str,
                            cmd: 'getZSMould',
                            param: {
                            }
                        }
                    }

                    api.openWin({
                        name: 'baseScreen',
                        url: 'common/baseScreen.html',
                        reload: true,
                        slidBackEnabled: false,
                        pageParam: obj
                    })
                },
                inputFocus() {
                    var that = this
                    APP.ajax('ZS_CardLogin', { P_Card: that.inputCode }, function (res) {
                        that.formData.EmplName = res.ds[0].Name
                        that.formData.EmplID = res.ds[0].pin

                        if (res.ds[0].status == 200) {

                            that.scanShow = false
                        } else {
                            vm.$toast(res.ds[0].msg);
                        }
                        that.inputCode = ''
                    })
                },
                confirmSub() {
                    var that = this
                    // if (!that.formData.WXStartTime) { //开始维修
                    //     var obj = {
                    //         MaintainEquipmentID: that.formData.MaintainEquipmentID,
                    //         pin: that.formData.EmplID
                    //     }
                    //     console.log('obj', JSON.stringify(obj))
                    //     APP.ajax('ZS_MJWXStrat', obj, function (res) {
                    //         console.log('res', JSON.stringify(res))
                    //         if (res.ds2[0].Column1 == '开始维修！') {
                    //             api.toast({
                    //                 msg: '模具开始维修！',
                    //                 duration: 2000,
                    //                 location: 'bottom'
                    //             });

                    //             that.formData.WXStartTime = APP.getFormatDateTime(new Date())

                    //             api.sendEvent({
                    //                 name: 'refreshMouldRepair'
                    //             })
                    //         } else {
                    //             api.toast({
                    //                 msg: '模具开始维修失败，请重试！',
                    //                 duration: 2000,
                    //                 location: 'bottom'
                    //             });
                    //             return false
                    //         }
                    //     })
                    // }
                    if (!that.formData.WXStartTime) { //开始维修\

                        var obj = {
                            pin: that.formData.EmplID,
                            MouldID: that.formData.MouldID,
                            UpkeepItemIDs: that.checkValue.map((item) => item.UpkeepItemName).join('~'),
                            Reason: that.formData.Reason,
                        }

                        console.log('obj', JSON.stringify(obj))
                        APP.ajax('ZS_MJWXStrat_1', obj, function (res) {
                            console.log('res', JSON.stringify(res))

                            api.toast({
                                msg: res.ds[0].Column1,
                                duration: 2000,
                                location: 'bottom'
                            });

                            that.formData.WXStartTime = APP.getFormatDateTime(new Date())

                            api.sendEvent({
                                name: 'refreshMouldRepair'
                            })
                            // if (res.ds2[0].Column1 == '开始维修！') {
                            //     api.toast({
                            //         msg: '模具开始维修！',
                            //         duration: 2000,
                            //         location: 'bottom'
                            //     });

                            //     that.formData.WXStartTime = APP.getFormatDateTime(new Date())

                            //     api.sendEvent({
                            //         name: 'refreshMouldRepair'
                            //     })
                            // } else {
                            //     api.toast({
                            //         msg: '模具开始维修失败，请重试！',
                            //         duration: 2000,
                            //         location: 'bottom'
                            //     });
                            //     return false
                            // }
                        })
                    }
                    else {
                        // that.scanShow = true
                        if (!that.formData.Reason) {
                            api.toast({
                                msg: '维修原因不能为空，请填写！',
                                duration: 2000,
                                location: 'bottom'
                            });
                        }

                        obj = {
                            FResultS: that.checkValue.map((item) => item.FResult).join('~'),
                            MaintainEquipmentID: that.formData.MaintainEquipmentID,
                            UpkeepItemIDS: that.checkValue.map((item) => item.UpkeepEquipmentDeID).join('~'),
                            pin: that.formData.EmplID,
                            Reason: that.formData.Reason,
                        }
                        console.log('obj', JSON.stringify(obj))
                        APP.ajax('ZS_MJWXEnd', obj, function (res) {
                            console.log('res', JSON.stringify(res))
                            if (res.ds[0].Column1 == '结束维修！') {
                                api.toast({
                                    msg: '模具结束维修！',
                                    duration: 2000,
                                    location: 'bottom'
                                });

                                that.formData.WXEndTime = APP.getFormatDateTime(new Date())

                                api.sendEvent({
                                    name: 'refreshMouldRepair'
                                })

                                api.sendEvent({
                                    name: 'refreshBrowser',
                                    extra: {
                                        breadData: {
                                            name: '模具维修明细',
                                            url: 'mouldRepairDetail',
                                            ZS_FunctionID: 0,
                                            click: true
                                        }
                                    }
                                })

                                api.closeFrame()
                            } else {
                                api.toast({
                                    msg: '模具结束维修失败，请重试！',
                                    duration: 2000,
                                    location: 'bottom'
                                });
                                return false
                            }
                        })
                    }
                },
            }
        })
    };
</script>

</html>